#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Created: Tue May 18 19:15:19 2010

from sys import argv
from PyQt4 import QtCore, QtGui

class FrameDiskManager(QtGui.QFrame):
    def __init__(self, connection, parent = None):
        super(FrameDiskManager, self).__init__(parent)
        self.setupUi(self)
        
        self.connection = connection
        self.diskManager = self.connection.root.Modules.DiskManagement.DiskManagement()
        devicesList = self.diskManager.listDevices()
        for device in devicesList:
            self.combo_selectDev.addItem(device)
            self.combo_partitions_mount.addItem(device)
            self.combo_partitions.addItem(device)
        
    def setupUi(self, disk_manager_frame):
        disk_manager_frame.setObjectName("disk_manager_frame")
        disk_manager_frame.resize(823, 580)
        disk_manager_frame.setFrameShape(QtGui.QFrame.StyledPanel)
        disk_manager_frame.setFrameShadow(QtGui.QFrame.Raised)
        self.horizontalLayout = QtGui.QHBoxLayout(disk_manager_frame)
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.gridLayout_7 = QtGui.QGridLayout()
        self.gridLayout_7.setObjectName("gridLayout_7")
        self.btn_diskInfo = QtGui.QPushButton(disk_manager_frame)
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap("icons/actions/edit-find.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.btn_diskInfo.setIcon(icon)
        self.btn_diskInfo.setObjectName("btn_diskInfo")
        self.gridLayout_7.addWidget(self.btn_diskInfo, 0, 0, 1, 1)
        self.combo_selectDev = QtGui.QComboBox(disk_manager_frame)
        self.combo_selectDev.setObjectName("combo_selectDev")
        self.combo_selectDev.addItem("")
        self.gridLayout_7.addWidget(self.combo_selectDev, 0, 1, 1, 1)
        self.plain_devInfo = QtGui.QTextEdit(disk_manager_frame)
        self.plain_devInfo.setObjectName("plain_devInfo")
        self.plain_devInfo.setFixedSize(500, 580)
        self.gridLayout_7.addWidget(self.plain_devInfo, 1, 0, 1, 3)
        self.horizontalLayout.addLayout(self.gridLayout_7)
        self.verticalLayout = QtGui.QVBoxLayout()
        self.verticalLayout.setObjectName("verticalLayout")
        self.tabWidget = QtGui.QTabWidget(disk_manager_frame)
        self.tabWidget.setObjectName("tabWidget")
        self.tab_2 = QtGui.QWidget()
        self.tab_2.setObjectName("tab_2")
        self.gridLayout = QtGui.QGridLayout(self.tab_2)
        self.gridLayout.setObjectName("gridLayout")
        self.label_26 = QtGui.QLabel(self.tab_2)
        self.label_26.setObjectName("label_26")
        self.gridLayout.addWidget(self.label_26, 0, 0, 1, 1)
        self.combo_partitions_mount = QtGui.QComboBox(self.tab_2)
        self.combo_partitions_mount.setObjectName("combo_partitions_mount")
        self.combo_partitions_mount.addItem("")
        self.gridLayout.addWidget(self.combo_partitions_mount, 0, 1, 1, 1)
        self.label_25 = QtGui.QLabel(self.tab_2)
        self.label_25.setObjectName("label_25")
        self.gridLayout.addWidget(self.label_25, 2, 0, 1, 1)
        self.text_mountPointPath = QtGui.QLineEdit(self.tab_2)
        self.text_mountPointPath.setObjectName("text_mountPointPath")
        self.gridLayout.addWidget(self.text_mountPointPath, 2, 1, 1, 1)
        self.checkBox_formatType = QtGui.QCheckBox(self.tab_2)
        self.checkBox_formatType.setObjectName("checkBox_formatType")
        self.gridLayout.addWidget(self.checkBox_formatType, 3, 0, 1, 1)
        self.text_formatType = QtGui.QLineEdit(self.tab_2)
        self.text_formatType.setObjectName("text_formatType")
        self.gridLayout.addWidget(self.text_formatType, 3, 1, 1, 1)
        self.checkBox_options = QtGui.QCheckBox(self.tab_2)
        self.checkBox_options.setObjectName("checkBox_options")
        self.gridLayout.addWidget(self.checkBox_options, 4, 0, 1, 1)
        self.text_mountOptions = QtGui.QLineEdit(self.tab_2)
        self.text_mountOptions.setObjectName("text_mountOptions")
        self.gridLayout.addWidget(self.text_mountOptions, 4, 1, 1, 1)
        self.checkBox_startUpmount = QtGui.QCheckBox(self.tab_2)
        self.checkBox_startUpmount.setObjectName("checkBox_startUpmount")
        self.gridLayout.addWidget(self.checkBox_startUpmount, 5, 0, 1, 2)
        self.btn_mount = QtGui.QPushButton(self.tab_2)
        icon1 = QtGui.QIcon()
        icon1.addPixmap(QtGui.QPixmap("icons/actions/insert-link.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.btn_mount.setIcon(icon1)
        self.btn_mount.setObjectName("btn_mount")
        self.gridLayout.addWidget(self.btn_mount, 5, 2, 1, 1)
        self.writtenPartition = QtGui.QLineEdit(self.tab_2)
        self.writtenPartition.setObjectName("writtenPartition")
        self.gridLayout.addWidget(self.writtenPartition, 1, 1, 1, 1)
        self.tabWidget.addTab(self.tab_2, "")
        self.tab = QtGui.QWidget()
        self.tab.setObjectName("tab")
        self.gridLayout_2 = QtGui.QGridLayout(self.tab)
        self.gridLayout_2.setObjectName("gridLayout_2")
        self.chkbox_unmountPartition = QtGui.QCheckBox(self.tab)
        self.chkbox_unmountPartition.setObjectName("chkbox_unmountPartition")
        self.gridLayout_2.addWidget(self.chkbox_unmountPartition, 0, 0, 1, 1)
        self.text_unmountPartition = QtGui.QLineEdit(self.tab)
        self.text_unmountPartition.setObjectName("text_unmountPartition")
        self.gridLayout_2.addWidget(self.text_unmountPartition, 0, 1, 1, 1)
        self.chkbox_unmountMP = QtGui.QCheckBox(self.tab)
        self.chkbox_unmountMP.setObjectName("chkbox_unmountMP")
        self.gridLayout_2.addWidget(self.chkbox_unmountMP, 1, 0, 1, 1)
        self.text_unmountMP = QtGui.QLineEdit(self.tab)
        self.text_unmountMP.setObjectName("text_unmountMP")
        self.gridLayout_2.addWidget(self.text_unmountMP, 1, 1, 1, 1)
        self.btn_unmount = QtGui.QPushButton(self.tab)
        icon2 = QtGui.QIcon()
        icon2.addPixmap(QtGui.QPixmap("icons/actions/list-remove.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.btn_unmount.setIcon(icon2)
        self.btn_unmount.setObjectName("btn_unmount")
        self.gridLayout_2.addWidget(self.btn_unmount, 2, 2, 1, 1)
        self.tabWidget.addTab(self.tab, "")
        self.verticalLayout.addWidget(self.tabWidget)
        self.tabWidget_2 = QtGui.QTabWidget(disk_manager_frame)
        self.tabWidget_2.setObjectName("tabWidget_2")
        self.tab_3 = QtGui.QWidget()
        self.tab_3.setObjectName("tab_3")
        self.gridLayout_3 = QtGui.QGridLayout(self.tab_3)
        self.gridLayout_3.setObjectName("gridLayout_3")
        self.label_21 = QtGui.QLabel(self.tab_3)
        self.label_21.setObjectName("label_21")
        self.gridLayout_3.addWidget(self.label_21, 0, 0, 1, 1)
        self.text_devPath_addNew = QtGui.QLineEdit(self.tab_3)
        self.text_devPath_addNew.setObjectName("text_devPath_addNew")
        self.gridLayout_3.addWidget(self.text_devPath_addNew, 0, 1, 1, 1)
        self.label_23 = QtGui.QLabel(self.tab_3)
        self.label_23.setObjectName("label_23")
        self.gridLayout_3.addWidget(self.label_23, 1, 0, 1, 1)
        self.text_startSize_addnew = QtGui.QLineEdit(self.tab_3)
        self.text_startSize_addnew.setObjectName("text_startSize_addnew")
        self.gridLayout_3.addWidget(self.text_startSize_addnew, 1, 1, 1, 1)
        self.label_22 = QtGui.QLabel(self.tab_3)
        self.label_22.setObjectName("label_22")
        self.gridLayout_3.addWidget(self.label_22, 2, 0, 1, 1)
        self.combo_partitionsTypes = QtGui.QComboBox(self.tab_3)
        self.combo_partitionsTypes.setObjectName("combo_partitionsTypes")
        self.combo_partitionsTypes.addItem("")
        self.combo_partitionsTypes.addItem("")
        self.combo_partitionsTypes.addItem("")
        self.combo_partitionsTypes.addItem("")
        self.combo_partitionsTypes.addItem("")
        self.combo_partitionsTypes.setItemText(4, "")
        self.gridLayout_3.addWidget(self.combo_partitionsTypes, 2, 1, 1, 1)
        self.label_24 = QtGui.QLabel(self.tab_3)
        self.label_24.setObjectName("label_24")
        self.gridLayout_3.addWidget(self.label_24, 3, 0, 1, 1)
        self.text_endSize_addnew = QtGui.QLineEdit(self.tab_3)
        self.text_endSize_addnew.setObjectName("text_endSize_addnew")
        self.gridLayout_3.addWidget(self.text_endSize_addnew, 3, 1, 1, 1)
        self.btn_addnew = QtGui.QPushButton(self.tab_3)
        icon3 = QtGui.QIcon()
        icon3.addPixmap(QtGui.QPixmap("icons/actions/tools-wizard.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.btn_addnew.setIcon(icon3)
        self.btn_addnew.setObjectName("btn_addnew")
        self.gridLayout_3.addWidget(self.btn_addnew, 4, 2, 1, 1)
        self.tabWidget_2.addTab(self.tab_3, "")
        
#        self.tab_4 = QtGui.QWidget()
#        self.tab_4.setObjectName("tab_4")
#        self.gridLayout_4 = QtGui.QGridLayout(self.tab_4)
#        self.gridLayout_4.setObjectName("gridLayout_4")
#        self.label_17 = QtGui.QLabel(self.tab_4)
#        self.label_17.setObjectName("label_17")
#        self.gridLayout_4.addWidget(self.label_17, 0, 0, 1, 1)
#        self.text_devPath_resize = QtGui.QLineEdit(self.tab_4)
#        self.text_devPath_resize.setObjectName("text_devPath_resize")
#        self.gridLayout_4.addWidget(self.text_devPath_resize, 0, 1, 1, 1)
#        self.label_18 = QtGui.QLabel(self.tab_4)
#        self.label_18.setObjectName("label_18")
#        self.gridLayout_4.addWidget(self.label_18, 1, 0, 1, 1)
#        self.text_partNum_resize = QtGui.QLineEdit(self.tab_4)
#        self.text_partNum_resize.setObjectName("text_partNum_resize")
#        self.gridLayout_4.addWidget(self.text_partNum_resize, 1, 1, 1, 1)
#        self.label_20 = QtGui.QLabel(self.tab_4)
#        self.label_20.setObjectName("label_20")
#        self.gridLayout_4.addWidget(self.label_20, 3, 0, 1, 1)
#        self.text_endSize_resize = QtGui.QLineEdit(self.tab_4)
#        self.text_endSize_resize.setObjectName("text_endSize_resize")
#        self.gridLayout_4.addWidget(self.text_endSize_resize, 3, 1, 1, 1)
#        self.label_19 = QtGui.QLabel(self.tab_4)
#        self.label_19.setObjectName("label_19")
#        self.gridLayout_4.addWidget(self.label_19, 2, 0, 1, 1)
#        self.text_startSize_resize = QtGui.QLineEdit(self.tab_4)
#        self.text_startSize_resize.setObjectName("text_startSize_resize")
#        self.gridLayout_4.addWidget(self.text_startSize_resize, 2, 1, 1, 1)
#        self.btn_resizePart = QtGui.QPushButton(self.tab_4)
#        icon4 = QtGui.QIcon()
#        icon4.addPixmap(QtGui.QPixmap("icons/actions/go-last.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
#        self.btn_resizePart.setIcon(icon4)
#        self.btn_resizePart.setObjectName("btn_resizePart")
#        self.gridLayout_4.addWidget(self.btn_resizePart, 4, 2, 1, 1)
#        self.tabWidget_2.addTab(self.tab_4, "")
        self.tab_5 = QtGui.QWidget()
        self.tab_5.setObjectName("tab_5")
        self.gridLayout_5 = QtGui.QGridLayout(self.tab_5)
        self.gridLayout_5.setObjectName("gridLayout_5")
        self.label_13 = QtGui.QLabel(self.tab_5)
        self.label_13.setObjectName("label_13")
        self.gridLayout_5.addWidget(self.label_13, 0, 0, 1, 1)
        self.text_devPath_delete = QtGui.QLineEdit(self.tab_5)
        self.text_devPath_delete.setObjectName("text_devPath_delete")
        self.gridLayout_5.addWidget(self.text_devPath_delete, 0, 1, 1, 1)
        self.label_14 = QtGui.QLabel(self.tab_5)
        self.label_14.setObjectName("label_14")
        self.gridLayout_5.addWidget(self.label_14, 1, 0, 1, 1)
        self.text_partNum_delete = QtGui.QLineEdit(self.tab_5)
        self.text_partNum_delete.setObjectName("text_partNum_delete")
        self.gridLayout_5.addWidget(self.text_partNum_delete, 1, 1, 1, 1)
        self.btn_delDev = QtGui.QPushButton(self.tab_5)
        icon5 = QtGui.QIcon()
        icon5.addPixmap(QtGui.QPixmap("icons/actions/edit-bomb.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.btn_delDev.setIcon(icon5)
        self.btn_delDev.setObjectName("btn_delDev")
        self.gridLayout_5.addWidget(self.btn_delDev, 2, 2, 1, 1)
        self.tabWidget_2.addTab(self.tab_5, "")
        self.tab_6 = QtGui.QWidget()
        self.tab_6.setObjectName("tab_6")
        self.gridLayout_6 = QtGui.QGridLayout(self.tab_6)
        self.gridLayout_6.setObjectName("gridLayout_6")
        self.label_46 = QtGui.QLabel(self.tab_6)
        self.label_46.setObjectName("label_46")
        self.gridLayout_6.addWidget(self.label_46, 0, 0, 1, 1)
        self.combo_partitions = QtGui.QComboBox(self.tab_6)
        self.combo_partitions.setObjectName("combo_partitions")
        self.combo_partitions.addItem("")
        self.gridLayout_6.addWidget(self.combo_partitions, 0, 1, 1, 1)
        self.label_47 = QtGui.QLabel(self.tab_6)
        self.label_47.setObjectName("label_47")
        self.gridLayout_6.addWidget(self.label_47, 2, 0, 1, 1)
        self.combo_formats_2 = QtGui.QComboBox(self.tab_6)
        self.combo_formats_2.setObjectName("combo_formats_2")
        self.combo_formats_2.addItem("")
        self.combo_formats_2.addItem("")
        self.combo_formats_2.addItem("")
        self.combo_formats_2.addItem("")
        self.combo_formats_2.addItem("")
        self.combo_formats_2.addItem("")
        self.combo_formats_2.addItem("")
        self.combo_formats_2.addItem("")
        self.combo_formats_2.addItem("")
        self.gridLayout_6.addWidget(self.combo_formats_2, 2, 1, 1, 1)
        self.btn_format = QtGui.QPushButton(self.tab_6)
        icon6 = QtGui.QIcon()
        icon6.addPixmap(QtGui.QPixmap("icons/actions/transform-move.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.btn_format.setIcon(icon6)
        self.btn_format.setObjectName("btn_format")
        self.gridLayout_6.addWidget(self.btn_format, 3, 2, 1, 1)
        self.formateWrittenPartition = QtGui.QLineEdit(self.tab_6)
        self.formateWrittenPartition.setObjectName("formateWrittenPartition")
        self.gridLayout_6.addWidget(self.formateWrittenPartition, 1, 1, 1, 1)
        self.tabWidget_2.addTab(self.tab_6, "")
        self.verticalLayout.addWidget(self.tabWidget_2)
        self.horizontalLayout.addLayout(self.verticalLayout)

        ############################# Signals connections ############################
        self.connect(self.btn_diskInfo, QtCore.SIGNAL('clicked()'), self.diskInfo)
        self.connect(self.btn_mount, QtCore.SIGNAL('clicked()'), self.mountPartition)
        self.connect(self.btn_unmount, QtCore.SIGNAL('clicked()'), self.umountPartition)
        self.connect(self.btn_addnew, QtCore.SIGNAL('clicked()'), self.addPartition)
        #self.connect(self.btn_resizePart, QtCore.SIGNAL('clicked()'), self.resizePartition)
        self.connect(self.btn_delDev, QtCore.SIGNAL('clicked()'), self.deletePartition)
        self.connect(self.btn_format, QtCore.SIGNAL('clicked()'), self.formatPartition)
        ##############################################################################
        self.retranslateUi(disk_manager_frame)
        self.tabWidget.setCurrentIndex(0)
        self.tabWidget_2.setCurrentIndex(0)
        QtCore.QMetaObject.connectSlotsByName(disk_manager_frame)

    def retranslateUi(self, disk_manager_frame):
        disk_manager_frame.setWindowTitle(QtGui.QApplication.translate("disk_manager_frame", "Frame", None, QtGui.QApplication.UnicodeUTF8))
        self.btn_diskInfo.setText(QtGui.QApplication.translate("disk_manager_frame", "get disk info", None, QtGui.QApplication.UnicodeUTF8))
        self.combo_selectDev.setItemText(0, QtGui.QApplication.translate("disk_manager_frame", "select device..", None, QtGui.QApplication.UnicodeUTF8))
        self.label_26.setText(QtGui.QApplication.translate("disk_manager_frame", "Select partition", None, QtGui.QApplication.UnicodeUTF8))
        self.combo_partitions_mount.setItemText(0, QtGui.QApplication.translate("disk_manager_frame", ".....", None, QtGui.QApplication.UnicodeUTF8))
        self.label_25.setText(QtGui.QApplication.translate("disk_manager_frame", "Mount point path", None, QtGui.QApplication.UnicodeUTF8))
        self.checkBox_formatType.setText(QtGui.QApplication.translate("disk_manager_frame", "Format type", None, QtGui.QApplication.UnicodeUTF8))
        self.text_formatType.setText(QtGui.QApplication.translate("disk_manager_frame", "auto", None, QtGui.QApplication.UnicodeUTF8))
        self.checkBox_options.setText(QtGui.QApplication.translate("disk_manager_frame", "Options", None, QtGui.QApplication.UnicodeUTF8))
        self.text_mountOptions.setText(QtGui.QApplication.translate("disk_manager_frame", "defaults", None, QtGui.QApplication.UnicodeUTF8))
        self.checkBox_startUpmount.setText(QtGui.QApplication.translate("disk_manager_frame", "Mount on startup", None, QtGui.QApplication.UnicodeUTF8))
        self.btn_mount.setText(QtGui.QApplication.translate("disk_manager_frame", "Mount", None, QtGui.QApplication.UnicodeUTF8))
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2), QtGui.QApplication.translate("disk_manager_frame", "Mount Partition", None, QtGui.QApplication.UnicodeUTF8))
        self.chkbox_unmountPartition.setText(QtGui.QApplication.translate("disk_manager_frame", "Partition", None, QtGui.QApplication.UnicodeUTF8))
        self.chkbox_unmountMP.setText(QtGui.QApplication.translate("disk_manager_frame", "Mount point", None, QtGui.QApplication.UnicodeUTF8))
        self.btn_unmount.setText(QtGui.QApplication.translate("disk_manager_frame", "Unmount", None, QtGui.QApplication.UnicodeUTF8))
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab), QtGui.QApplication.translate("disk_manager_frame", "Unmount Partition", None, QtGui.QApplication.UnicodeUTF8))
        self.label_21.setText(QtGui.QApplication.translate("disk_manager_frame", "Device path", None, QtGui.QApplication.UnicodeUTF8))
        self.label_23.setText(QtGui.QApplication.translate("disk_manager_frame", "Start size", None, QtGui.QApplication.UnicodeUTF8))
        self.label_22.setText(QtGui.QApplication.translate("disk_manager_frame", "Partiton type", None, QtGui.QApplication.UnicodeUTF8))
        self.combo_partitionsTypes.setItemText(0, QtGui.QApplication.translate("disk_manager_frame", "....", None, QtGui.QApplication.UnicodeUTF8))
        self.combo_partitionsTypes.setItemText(1, QtGui.QApplication.translate("disk_manager_frame", "primary", None, QtGui.QApplication.UnicodeUTF8))
        self.combo_partitionsTypes.setItemText(2, QtGui.QApplication.translate("disk_manager_frame", "extended", None, QtGui.QApplication.UnicodeUTF8))
        self.combo_partitionsTypes.setItemText(3, QtGui.QApplication.translate("disk_manager_frame", "logical", None, QtGui.QApplication.UnicodeUTF8))
        self.label_24.setText(QtGui.QApplication.translate("disk_manager_frame", "End size", None, QtGui.QApplication.UnicodeUTF8))
        self.btn_addnew.setText(QtGui.QApplication.translate("disk_manager_frame", "Add", None, QtGui.QApplication.UnicodeUTF8))
        self.tabWidget_2.setTabText(self.tabWidget_2.indexOf(self.tab_3), QtGui.QApplication.translate("disk_manager_frame", "Add Partition", None, QtGui.QApplication.UnicodeUTF8))
#        self.label_17.setText(QtGui.QApplication.translate("disk_manager_frame", "Device path", None, QtGui.QApplication.UnicodeUTF8))
#        self.label_18.setText(QtGui.QApplication.translate("disk_manager_frame", "Partition number", None, QtGui.QApplication.UnicodeUTF8))
#        self.label_20.setText(QtGui.QApplication.translate("disk_manager_frame", "End size", None, QtGui.QApplication.UnicodeUTF8))
#        self.label_19.setText(QtGui.QApplication.translate("disk_manager_frame", "Start size", None, QtGui.QApplication.UnicodeUTF8))
#        self.btn_resizePart.setText(QtGui.QApplication.translate("disk_manager_frame", "Resize", None, QtGui.QApplication.UnicodeUTF8))
#        self.tabWidget_2.setTabText(self.tabWidget_2.indexOf(self.tab_4), QtGui.QApplication.translate("disk_manager_frame", "Resize Partition", None, QtGui.QApplication.UnicodeUTF8))
        #self.label_13.setText(QtGui.QApplication.translate("disk_manager_frame", "Device path", None, QtGui.QApplication.UnicodeUTF8))
        self.label_14.setText(QtGui.QApplication.translate("disk_manager_frame", "Partition number", None, QtGui.QApplication.UnicodeUTF8))
        self.btn_delDev.setText(QtGui.QApplication.translate("disk_manager_frame", "Delete", None, QtGui.QApplication.UnicodeUTF8))
        self.tabWidget_2.setTabText(self.tabWidget_2.indexOf(self.tab_5), QtGui.QApplication.translate("disk_manager_frame", "Delete Partition", None, QtGui.QApplication.UnicodeUTF8))
        self.label_46.setText(QtGui.QApplication.translate("disk_manager_frame", "select Partition", None, QtGui.QApplication.UnicodeUTF8))
        self.combo_partitions.setItemText(0, QtGui.QApplication.translate("disk_manager_frame", "..", None, QtGui.QApplication.UnicodeUTF8))
        self.label_47.setText(QtGui.QApplication.translate("disk_manager_frame", "Format type", None, QtGui.QApplication.UnicodeUTF8))
        self.combo_formats_2.setItemText(0, QtGui.QApplication.translate("disk_manager_frame", "..", None, QtGui.QApplication.UnicodeUTF8))
        self.combo_formats_2.setItemText(1, QtGui.QApplication.translate("disk_manager_frame", "ext2", None, QtGui.QApplication.UnicodeUTF8))
        self.combo_formats_2.setItemText(2, QtGui.QApplication.translate("disk_manager_frame", "ext3", None, QtGui.QApplication.UnicodeUTF8))
        self.combo_formats_2.setItemText(3, QtGui.QApplication.translate("disk_manager_frame", "ext4", None, QtGui.QApplication.UnicodeUTF8))
        self.combo_formats_2.setItemText(4, QtGui.QApplication.translate("disk_manager_frame", "jfs", None, QtGui.QApplication.UnicodeUTF8))
        self.combo_formats_2.setItemText(5, QtGui.QApplication.translate("disk_manager_frame", "ntfs", None, QtGui.QApplication.UnicodeUTF8))
        self.combo_formats_2.setItemText(6, QtGui.QApplication.translate("disk_manager_frame", "vfat", None, QtGui.QApplication.UnicodeUTF8))
        self.combo_formats_2.setItemText(7, QtGui.QApplication.translate("disk_manager_frame", "xfs", None, QtGui.QApplication.UnicodeUTF8))
        self.combo_formats_2.setItemText(8, QtGui.QApplication.translate("disk_manager_frame", "swap", None, QtGui.QApplication.UnicodeUTF8))
        self.btn_format.setText(QtGui.QApplication.translate("disk_manager_frame", "Format", None, QtGui.QApplication.UnicodeUTF8))
        self.tabWidget_2.setTabText(self.tabWidget_2.indexOf(self.tab_6), QtGui.QApplication.translate("disk_manager_frame", "Format", None, QtGui.QApplication.UnicodeUTF8))
        ############# set tool tips #######################
        self.writtenPartition.setToolTip(QtGui.QApplication.translate("Form", "pass the partition if you didn't find it on the partitions list ", None, QtGui.QApplication.UnicodeUTF8))
        self.text_mountPointPath.setToolTip(QtGui.QApplication.translate("Form", "pass the mount point for the selected partition", None, QtGui.QApplication.UnicodeUTF8))
        self.text_formatType.setToolTip(QtGui.QApplication.translate("Form", "pass the format type for the selected partition . Example : ntfs , vfat , ext3 , ..", None, QtGui.QApplication.UnicodeUTF8))
        self.text_mountOptions.setToolTip(QtGui.QApplication.translate("Form", "pass the options you want to set for the selected partition. Example: ro , rw , defaults", None, QtGui.QApplication.UnicodeUTF8))
        self.text_unmountPartition.setToolTip(QtGui.QApplication.translate("Form", "pass the partition path you want to unmount", None, QtGui.QApplication.UnicodeUTF8))
        self.text_unmountMP.setToolTip(QtGui.QApplication.translate("Form", "pass the mount point you want to unmount", None, QtGui.QApplication.UnicodeUTF8))      
        
        self.text_devPath_addNew.setToolTip(QtGui.QApplication.translate("Form", "pass the device path. Example: /dev/hda", None, QtGui.QApplication.UnicodeUTF8))
        self.text_startSize_addnew.setToolTip(QtGui.QApplication.translate("Form", "pass the start size of the partition you want to add with migabytes", None, QtGui.QApplication.UnicodeUTF8))
        self.text_endSize_addnew.setToolTip(QtGui.QApplication.translate("Form", "pass the end size of the partition you want to add with migabytes", None, QtGui.QApplication.UnicodeUTF8))
#        self.text_devPath_resize.setToolTip(QtGui.QApplication.translate("Form", "pass the device path you want to resize. Example: /dev/sda ", None, QtGui.QApplication.UnicodeUTF8))
#        self.text_partNum_resize.setToolTip(QtGui.QApplication.translate("Form", "pass the the number of the partition you want to resize ", None, QtGui.QApplication.UnicodeUTF8))
#        self.text_startSize_resize.setToolTip(QtGui.QApplication.translate("Form", "pass the start size of the partition you want to resize with migabytes", None, QtGui.QApplication.UnicodeUTF8))
#        self.text_endSize_resize.setToolTip(QtGui.QApplication.translate("Form", "pass the end size of the partition you want to resize with migabytes", None, QtGui.QApplication.UnicodeUTF8))
        self.text_devPath_delete.setToolTip(QtGui.QApplication.translate("Form", "pass the device path of the partition you want to delete. Example:/dev/sda", None, QtGui.QApplication.UnicodeUTF8))
        self.text_partNum_delete.setToolTip(QtGui.QApplication.translate("Form", "pass the number of the partition you want to delete", None, QtGui.QApplication.UnicodeUTF8))
        self.formateWrittenPartition.setToolTip(QtGui.QApplication.translate("Form", "pass the path of the partition you want to format", None, QtGui.QApplication.UnicodeUTF8))
        
        
    def diskInfo(self):
        '''
        diskInfo(self)
            get all disk info or info of the selected partition
        '''
        devicesList = self.diskManager.listPartitionsInfo()
        self.plain_devInfo.setText(devicesList)
        
        currentDev = str(self.combo_selectDev.currentText())
        if currentDev != "select device..":
            deviceInfo = self.diskManager.listPartitionsInfo(devicePath=currentDev)
            self.plain_devInfo.setText(deviceInfo)
        


        
    def mountPartition(self):
        '''
        mountPartition(self)
            mount selected partition
        '''
        caurrentPartition = str(self.combo_partitions_mount.currentText())
        partitionPath = str(self.writtenPartition.text())
        mountPoint = str(self.text_mountPointPath.text())
        formateType = str(self.text_formatType.text())
        options = str(self.text_mountOptions.text())
        chkstateformateTypeText = str(self.checkBox_formatType.checkState())
        chkstateOptionsText = str(self.checkBox_options.checkState())
        chkstateStartupMount = str(self.checkBox_startUpmount.checkState())
        
        if (caurrentPartition != ".....") and (mountPoint !="") and (chkstateformateTypeText == "2") and (chkstateOptionsText == "2") and (chkstateStartupMount == "2"):
            if self.diskManager.mountPartiton(caurrentPartition, mountPoint, formatType=formateType, options=options , automate='automate'):
                QtGui.QMessageBox.information(self, "Information","Partition "+caurrentPartition+" is mounted successfully on "+mountPoint+"\n and successfully AUTOMATED")
                self.text_mountPointPath.clear()
                self.text_formatType.clear()
                self.text_mountOptions.clear()
            else:
                QtGui.QMessageBox.critical(self, "Exception","Can't automate mount the selected partition ")
        
        elif (partitionPath != ".....") and (mountPoint !="") and (chkstateformateTypeText == "2") and (chkstateOptionsText == "2") and (chkstateStartupMount == "2"):
            if self.diskManager.mountPartiton(partitionPath, mountPoint, formatType=formateType, options=options , automate='automate'):
                QtGui.QMessageBox.information(self, "Information","Partition "+partitionPath+" is mounted successfully on "+mountPoint+"\n and successfully AUTOMATED")
                self.writtenPartition.clear()
                self.text_mountPointPath.clear()
                self.text_formatType.clear()
                self.text_mountOptions.clear()
            else:
                QtGui.QMessageBox.critical(self, "Exception","Can't automate mount the selected partition ")
                
        elif (caurrentPartition != ".....") and (mountPoint !="") and (chkstateformateTypeText == "2") and (chkstateOptionsText == "2"):
            if self.diskManager.mountPartiton(caurrentPartition, mountPoint, formatType=formateType, options=options):
                QtGui.QMessageBox.information(self, "Information","Partition "+caurrentPartition+" is mounted successfully on "+mountPoint)
                self.text_mountPointPath.clear()
                self.text_formatType.clear()
                self.text_mountOptions.clear()
            else:
                QtGui.QMessageBox.critical(self, "Exception","Can't mount the selected partition ")

        elif (partitionPath != ".....") and (mountPoint !="") and (chkstateformateTypeText == "2") and (chkstateOptionsText == "2"):
            if self.diskManager.mountPartiton(partitionPath, mountPoint, formatType=formateType, options=options):
                QtGui.QMessageBox.information(self, "Information","Partition "+partitionPath+" is mounted successfully on "+mountPoint)
                self.writtenPartition.clear()
                self.text_mountPointPath.clear()
                self.text_formatType.clear()
                self.text_mountOptions.clear()
            else:
                QtGui.QMessageBox.critical(self, "Exception","Can't mount the selected partition ")

        elif (caurrentPartition != ".....") and (mountPoint !="") and (chkstateformateTypeText == "2"):
            if self.diskManager.mountPartiton(caurrentPartition, mountPoint, formatType=formateType):
                QtGui.QMessageBox.information(self, "Information","Partition "+caurrentPartition+" is mounted successfully on "+mountPoint)
                self.text_mountPointPath.clear()
                self.text_formatType.clear()
                self.text_mountOptions.clear()
            else:
                QtGui.QMessageBox.critical(self, "Exception","Can't mount the selected partition ")
                
        elif (partitionPath != ".....") and (mountPoint !="") and (chkstateformateTypeText == "2"):
            if self.diskManager.mountPartiton(partitionPath, mountPoint, formatType=formateType):
                QtGui.QMessageBox.information(self, "Information","Partition "+partitionPath+" is mounted successfully on "+mountPoint)
                self.writtenPartition.clear()
                self.text_mountPointPath.clear()
                self.text_formatType.clear()
                self.text_mountOptions.clear()
            else:
                QtGui.QMessageBox.critical(self, "Exception","Can't mount the selected partition ")

        elif (caurrentPartition != ".....") and (mountPoint !="") and (chkstateOptionsText == "2"):
            if self.diskManager.mountPartiton(caurrentPartition, mountPoint, options=options):
                QtGui.QMessageBox.information(self, "Information","Partition "+caurrentPartition+" is mounted successfully on "+mountPoint)
                self.text_mountPointPath.clear()
                self.text_formatType.clear()
                self.text_mountOptions.clear()
            else:
                QtGui.QMessageBox.critical(self, "Exception","Can't mount the selected partition ")
                
        elif (partitionPath != ".....") and (mountPoint !="") and (chkstateOptionsText == "2"):
            if self.diskManager.mountPartiton(partitionPath, mountPoint, options=options):
                QtGui.QMessageBox.information(self, "Information","Partition "+partitionPath+" is mounted successfully on "+mountPoint)
                self.text_mountPointPath.clear()
                self.text_formatType.clear()
                self.text_mountOptions.clear()
            else:
                QtGui.QMessageBox.critical(self, "Exception","Can't mount the selected partition ")

        elif (caurrentPartition != ".....") and (mountPoint !=""):
            if self.diskManager.mountPartiton(caurrentPartition, mountPoint):
                QtGui.QMessageBox.information(self, "Information","Partition "+caurrentPartition+" is mounted successfully on "+mountPoint)
                self.text_mountPointPath.clear()
                self.text_formatType.clear()
                self.text_mountOptions.clear()
            else:
                QtGui.QMessageBox.critical(self, "Exception","Can't mount the selected partition ")

        elif (partitionPath != "") and (mountPoint !=""):
            if self.diskManager.mountPartiton(partitionPath, mountPoint):
                QtGui.QMessageBox.information(self, "Information","Partition "+partitionPath+" is mounted successfully on "+mountPoint)
                self.text_mountPointPath.clear()
                self.text_formatType.clear()
                self.text_mountOptions.clear()
                
            else:
                QtGui.QMessageBox.critical(self, "Exception","Can't mount the selected partition ")
                
        else:
            QtGui.QMessageBox.critical(self, "Exception","You must complete the required fields")
                



    
    def umountPartition(self):
        '''
        umountPartition(self)
            unmount partition
        '''
        unmountedPart = str(self.text_unmountPartition.text())
        unmountedMP = str(self.text_unmountMP.text())
        chkstateUnmountPartition = str(self.chkbox_unmountPartition.checkState())
        chkstateUnmountMP = str(self.chkbox_unmountMP.checkState())
        
        if (chkstateUnmountPartition == "2") and (chkstateUnmountMP == "2"):
            if self.diskManager.unmountPartition(partitionPath=unmountedPart, mountPoint=unmountedMP):
                QtGui.QMessageBox.information(self, "Information","Partition "+unmountedPart+" unmounted successfully")
                self.text_unmountPartition.clear()
                self.text_unmountMP.clear()
            else:
                QtGui.QMessageBox.critical(self, "Exception","Can't Un mount the partition , may be already un mounted")
                
        elif (chkstateUnmountPartition == "2"):
            if self.diskManager.unmountPartition(partitionPath=unmountedPart):
                QtGui.QMessageBox.information(self, "Information","Partition "+unmountedPart+" unmounted successfully")
                self.text_unmountPartition.clear()
                self.text_unmountMP.clear()
            else:
                QtGui.QMessageBox.critical(self, "Exception","Can't Un mount the partition , may be already un mounted")
        
        elif (chkstateUnmountMP == "2"):
            if self.diskManager.unmountPartition(mountPoint=unmountedMP):
                QtGui.QMessageBox.information(self, "Information","Mount point "+unmountedMP+" unmounted successfully")
                self.text_unmountPartition.clear()
                self.text_unmountMP.clear()
            else:
                QtGui.QMessageBox.critical(self, "Exception","Can't Un mount the mount point , may be busy")
        
        else:
            QtGui.QMessageBox.critical(self, "Exception","You must complete the required fields")
    



    
    def addPartition(self):
        '''
        addPartition(self)
            add new partiton
        '''
        devicePath = str(self.text_devPath_addNew.text())
        startSize = str(self.text_startSize_addnew.text())
        partType = str(self.combo_partitionsTypes.currentText())
        endSize = str(self.text_endSize_addnew.text())
        
        if (devicePath != "") & (startSize != "") & (partType != "....") & (endSize != ""):
            if self.diskManager.addNewPartiton(devicePath=devicePath, partType=partType, startSize=startSize, endSize=endSize):
                '''clear the current items in the disk manager combo box'''
                self.combo_selectDev.clear()
                self.combo_partitions_mount.clear()
                self.combo_partitions.clear()
                '''fill the disk manager combo box with the current items in devices list'''
                devicesList = self.diskManager.listDevices()
                for device in devicesList:
                    self.combo_selectDev.addItem(device)
                    self.combo_partitions_mount.addItem(device)
                    self.combo_partitions.addItem(device)
                QtGui.QMessageBox.information(self, "Information","Partition is added successfully")
                '''get the current partitions table'''
                devicesList = self.diskManager.listPartitionsInfo()
                self.plain_devInfo.setText(devicesList)
                self.text_devPath_addNew.clear()
                self.text_startSize_addnew.clear()
                self.text_endSize_addnew.clear()
            else:
                QtGui.QMessageBox.critical(self, "Exception","Can't add the partition")
        else:
            QtGui.QMessageBox.critical(self, "Exception","You must complete the required fields")
    
    
    
    
    
#    def resizePartition(self):
#        '''
#        resizePartition(self)
#            resize partition
#        '''
#        devPath = str(self.text_devPath_resize.text())
#        partNumber = str(self.text_partNum_resize.text())
#        startSize = str(self.text_startSize_resize.text())
#        endSize = str(self.text_endSize_resize.text())
#        
#        if (devPath != "") & (partNumber != "") & (startSize != "") & (endSize != ""):
#            if self.diskManager.resizePartition(devicePath=devPath, partitionNumber=partNumber, startSize=startSize, endSize=endSize):
#                QtGui.QMessageBox.information(self, "Information","Partition "+devPath+partNumber+" resized successfully")
#                self.text_devPath_resize.clear()
#                self.text_partNum_resize.clear()
#                self.text_startSize_resize.clear()
#                self.text_endSize_resize.clear()
#            else:
#                QtGui.QMessageBox.critical(self, "Exception","Can't resize the partition")
#                
#        else:
#            QtGui.QMessageBox.critical(self, "Exception","You must complete the required fields")
    
    
    
    
    
    def deletePartition(self):
        '''
        deletePartition(self)
            delete partition or whole passed device
        '''
        devicePath = str(self.text_devPath_delete.text())
        partNumber = str(self.text_partNum_delete.text())
        
        if (devicePath != "") and (partNumber != ""):
            if self.diskManager.deletePartition(devicePath=devicePath, partitionNumber=partNumber):
                '''clear the current items in the disk manager combo box'''
                self.combo_selectDev.clear()
                self.combo_partitions_mount.clear()
                self.combo_partitions.clear()
                '''fill the disk manager combo box with the current items in devices list'''
                devicesList = self.diskManager.listDevices()
                for device in devicesList:
                    self.combo_selectDev.addItem(device)
                    self.combo_partitions_mount.addItem(device)
                    self.combo_partitions.addItem(device)
                QtGui.QMessageBox.information(self, "Information","Partition "+devicePath+partNumber+" deleted successfully")
                '''get the current partitions table'''
                devicesList = self.diskManager.listPartitionsInfo()
                self.plain_devInfo.setText(devicesList)
                self.text_devPath_delete.clear()
                self.text_partNum_delete.clear()
            else:
                QtGui.QMessageBox.critical(self, "Exception","Can't delete the partition "+devicePath+partNumber)
        
        elif (devicePath != ""):
            if self.diskManager.deletePartition(devicePath=devicePath):
                '''clear the current items in the disk manager combo box'''
                self.combo_selectDev.clear()
                self.combo_partitions_mount.clear()
                self.combo_partitions.clear()
                '''fill the disk manager combo box with the current items in devices list'''
                devicesList = self.diskManager.listDevices()
                for device in devicesList:
                    self.combo_selectDev.addItem(device)
                    self.combo_partitions_mount.addItem(device)
                    self.combo_partitions.addItem(device)
                QtGui.QMessageBox.information(self, "Information","All partitions on "+devicePath+" deleted successfully")
                '''get the current partitions table'''
                devicesList = self.diskManager.listPartitionsInfo()
                self.plain_devInfo.setText(devicesList)
                self.text_devPath_delete.clear()
            else:
                QtGui.QMessageBox.critical(self, "Exception","Can't perform the destroy action")
        
        else:
            QtGui.QMessageBox.critical(self, "Exception","You must complete the required fields")
    
    
    
    
    
    def formatPartition(self):
        '''
        formatPartition(self)
            format partition
        '''
        partition =  str(self.combo_partitions.currentText())
        partitionPath = str(self.formateWrittenPartition.text())
        formateType = str(self.combo_formats_2.currentText())
        
        if (partition != "..") & (formateType != ".."):
            if self.diskManager.formatPartition(partitionPath=partition, formatType=formateType):
                QtGui.QMessageBox.information(self, "Information","partition "+partition+" formated successfully")
            else:
                QtGui.QMessageBox.critical(self, "Exception","Can't formate the partition")
        
        elif (partitionPath != "") & (formateType != ".."):
            if self.diskManager.formatPartition(partitionPath=partitionPath, formatType=formateType):
                QtGui.QMessageBox.information(self, "Information","partition "+partitionPath+" formated successfully")
            else:
                QtGui.QMessageBox.critical(self, "Exception","Can't formate the partition")
                
                   
        else:
            QtGui.QMessageBox.critical(self, "Exception","You must complete the required fields")
            
        
if __name__ == '__main__':
    app = QtGui.QApplication(argv)
    abstract_window = FrameDiskManager()
    abstract_window.show()
    app.exec_()

